/**
 * 
 */
package com.nwpusp.model;

import java.util.ArrayList;
import java.util.Random;

import android.util.Log;

import com.nwpusp.model.location.Axis;
/**
 * @author JustinCao
 *
 */
public class TrackManager {
	
	private int trackNum = 0;
	private int totalWidth = 0;
	private int totalLength = 0;
	private int widthPerTrack = 0;
	
	public TrackManager(int trackNum, int totalWidth, int totalLength) {
		this.trackNum = trackNum;
		this.totalWidth = totalWidth;
		this.totalLength = totalLength;
		this.widthPerTrack = totalWidth / trackNum;
	}
	
	public ArrayList<Axis> getAllStaticEntityRawAxes() {
		Random rdm = new Random(System.currentTimeMillis());
		ArrayList<Axis> axes = new ArrayList<Axis>();
		int factor = (int)(Math.pow(2, (double)trackNum));
		for(int i = 1000; i <= totalLength - 4000; i += 5000) {
			calcRandomRawAxes(i, axes, rdm, factor);
		}
		return axes;
	}
	
	private void calcRandomRawAxes(int x, ArrayList<Axis> axes, Random rdm, int factor) {
        int intRd = Math.abs(rdm.nextInt()) % (3 * factor);
        Log.d("JustinRam", String.valueOf(intRd));
        if(intRd > 0 && intRd < factor) {
        	for(int tmp = 1, trackNo = 0; tmp < factor; tmp <<= 1, trackNo++) {
        		if((intRd & tmp) > 0) {
        			axes.add(new Axis(x, this.getYByTrackNo(trackNo), 0));
        		}
        	}
        }
	}
	
	public int getYByTrackNo(int trackNo) {
		return (trackNo * widthPerTrack);
	}
	
	public int getTrackNum() {
		return trackNum;
	}
}
